#include "Math.hpp"

namespace ge {

//----------------------------------------------------------------------------//
// Math
//----------------------------------------------------------------------------//

namespace Math {

//----------------------------------------------------------------------------//
uint32 _InitRandom( void ) 
{ 
     __asm rdtsc; 
}

static uint32 random_value = _InitRandom();

//----------------------------------------------------------------------------//
uint Random( uint32& _value )
{
     uint32 _tmp = _value + 12345;
     _tmp = ( _tmp + ( _tmp * ( _tmp << 1 ) ) ) >> 1;
     return ( _value = _tmp ) & 0xffffff;
}
//----------------------------------------------------------------------------//
int SignedRandom( uint32& _value )
{
     uint32 _tmp = _value + 12345;
     _tmp = ( _tmp + ( _tmp * ( _tmp << 1 ) ) ) >> 1;
     return ( ( _value = _tmp ) & 0xffffff ) - 0x7fffff;
}
//----------------------------------------------------------------------------//
uint Random( void )
{
     return Random( random_value );
}
//----------------------------------------------------------------------------//
int SignedRandom( void )
{
     return SignedRandom( random_value );
}
//----------------------------------------------------------------------------//

} // namespace Math

} // namespace ge
